package com.wn.controller;

import com.wn.model.R;
import com.wn.model.User;
import com.wn.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yellow Docter
 * @date 2022 -06-10
 * @desc
 */

@RestController
public class ApiController {

    @Autowired
    private IUserService userService;
    /**
     * 根据id查询用户信息
     * http://localhost:8088/api/user/1
     *
     * @param id
     * @return
     */
    @GetMapping("/api/user/{id}")
    public User getUser(@PathVariable("id") Long id) {
        return userService.getById(id);
    }

    /**
     * 根据id删除
     * http://localhost:8088/api/del/32423423
     * @param id
     * @return
     */
    @PostMapping("/api/user/del/{id}")
    public R deleteByID(@PathVariable("id") Long id) {
        boolean b = userService.removeById(id);
        return b ? R.OK():R.ERROR();
    }
}
